% function finetuning
caffe = '/home/mdc/caffe-master/build/tools/caffe';
% solverstate = '/home/mdc/curwork/Matlab/Work/Caffe/Matlab/+mycaffe_iter_6064.solverstate';
solverstate = [];

% caffe.Solver('xx')
LCNN_ModelPath = fullfile(mycaffe.modelpath, 'LightenedCNN');
solver = fullfile(LCNN_ModelPath, 'LCNN_solver.prototxt');
% weights = fullfile(LCNN_ModelPath, 'LightenedCNN_B.caffemodel');
weights = fullfile(LCNN_ModelPath, 'LCNN.caffemodel');
logfile = fullfile(mycaffe.path, 'mylog.log');

%%
% cmd_train = sprintf('caffe train -solver %s -weights %s -gpu 0 2>%s', solver, weights, logfile);
if isempty(solverstate)
    cmd_train = sprintf('%s train --solver %s --weights %s --gpu 0 2>&1 | tee %s', ...
        caffe, solver, weights, logfile);
else
    cmd_train = sprintf('%s train --solver %s --snapshot %s -gpu 0 2>&1 | tee %s', ...
        caffe, solver, solverstate, logfile);
end

%%
train_sh = fullfile('~', 'train.sh');

fid = fopen(train_sh, 'w');
fprintf(fid, '#! /usr/bin/env sh\n');
fprintf(fid, [cmd_train '\n']);
fclose(fid);
system(['chmod 777 ' train_sh]);

% cmd_train = sprintf('caffe train -solver %s -weights %s 2>%s', solver, weights, logfile);
% system(cmd_train)
